package com.cooper.controllers.seller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.controllers.Controller;
import com.cooper.core.JsonResult;
import com.cooper.helper.SavedItem;
import com.cooper.service.admin.SavedService;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.rest.Post;

public class SavedController extends Controller {
	
	@Autowired
	private SavedService savedService;

	@Post
	public JsonResult execute(Invocation inv, SavedItem savedItem) {
		JsonResult json = new JsonResult();
		if(StringUtils.isBlank(savedItem.getResName()) || StringUtils.isBlank(savedItem.getKey())){
			json.setMessage("CAN'T SAVED ITEM WITHOUT RESOURCE TYPE OR KEY!");
		} else {
			this.savedService.doSave(savedItem.getResName(), savedItem.getKey(), savedItem.getValue());
			json.setSuccess(true);
		}
		return json;
	}
	
}

